// pages/score_detail/score_detail.js
const request = require('../../utils/promise.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userId: null,
    projectId: null,
    scoreArr: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) { 
    this.setData({
      userId: options.userId,
      projectId: options.projectId
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.reqProjectScoreDetail();
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.reqProjectScoreDetail();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面被用户分享时执行
   */
  onShareAppMessage() {
    return {
      title: '积分详情'
    }
  },

  /**
   * 分享到朋友圈
   */
  onShareTimeline() {
    return {
      title: '积分详情'
    }
  },

  /**
   * 请求加载项目(项目)积分记录
   */
  reqProjectScoreDetail() {
    const param = {projectId: this.data.projectId, userId: this.data.userId};
    request.GET('/project/projectScoreDetail', param).then(res => {
      // console.log(res)
      if (res.data.resCode==200) {
        this.setData({
          scoreArr: res.data.scoreArrList
        })
      } else {
        wx.showToast({
          title: '数据加载异常',
          icon: 'error',
          duration: 1500
        })
      }
    })
  },

  /**
   * 点击查看积分添加记录描述
   */
  clickViewDetail(e) {
    wx.navigateTo({
      url: '/pages/score_detail_desc/score_detail_desc?id='+ e.currentTarget.dataset.id,
    })
  },
  
})